package generadordescktop;

import generadorabm.Controladora;
import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Agustin
 */
public class ModeloComboTipo extends AbstractListModel implements ComboBoxModel {

    boolean loEncontro;
    String[] items;//cadena q recibira los datos a mostrar.
    String itemSelecionado = null;

    public ModeloComboTipo() {
        items = new String[0];
        this.agregaItem("public");
        this.agregaItem("private");
        this.agregaItem("protected");      
    }

    public Object getElementAt(int index) {
       
        return items[index];
    }

    public int getSize() {
        return items.length;
    }

    public void setSelectedItem(Object item) {
        itemSelecionado = (String) item;
        fireContentsChanged(this, -1, -1);
    }

    public void agregaItem(String cadena) {
        String[] nuevoItems = new String[items.length + 1];
        for (int i = 0; i < items.length; i++) {
            nuevoItems[i] = items[i];
        }
        nuevoItems[items.length] = cadena;
        items = nuevoItems;
        fireContentsChanged(this, -1, -1);
    }

    public boolean buscaItem(String itemABuscar) {
        for (int i = 0; i < items.length; i++) {
            if (itemABuscar == items[i]) {
                loEncontro = true;
                break;
            } else {
                loEncontro = false;
            }
        }
        return loEncontro;
    }

    public Object getSelectedItem() { //metodo implementado por la interface  JComboBoxModel
        return itemSelecionado;

    }
}
